import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author LS
 * @version 1.0
 * @description:
 * @date 2021/5/3 上午10:26
 */
public class MyProxy implements InvocationHandler {

    private Object obj;

    public MyProxy(Object obj) {
        this.obj = obj;

    }

    public <T> T getProxy() {
        return (T) Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        obj = method.invoke(obj, args);
        System.out.println("after");
        return obj;
    }
}

class Test{
    public static void main(String[] args) {
        Ipeople proxy = new MyProxy(new Man()).getProxy();
        proxy.doSomething();
    }
}
